MERGE INTO DISTRIBUTION_DESTINATION D 
 USING ( 
	SELECT 
		'CH_FEED' as "DISTRIBUTION_TYPE",
		'IRMS_FEED_DEST' as "DESTINATION_ID",
		NULL as "TO_DIRECTORY",
		NULL as "EMAIL_LIST",
		'CH_RTI' as "FTP_LOGIN_ID",
		'/access/adoldev/feeds' as "FTP_DESTINATION",
		'destination_id_seq.NEXTVAL' as "DISTRIBUTION_ID"
 FROM DUAL) S 
ON (
	S.DISTRIBUTION_TYPE = D.DISTRIBUTION_TYPE)
WHEN MATCHED THEN 
	UPDATE SET 
		D.DESTINATION_ID = S.DESTINATION_ID, 
		D.TO_DIRECTORY = S.TO_DIRECTORY, 
		D.EMAIL_LIST = S.EMAIL_LIST, 
		D.FTP_LOGIN_ID = S.FTP_LOGIN_ID, 
		D.FTP_DESTINATION = S.FTP_DESTINATION, 
		D.DISTRIBUTION_ID = S.DISTRIBUTION_ID
WHEN NOT MATCHED THEN 
	INSERT (
		DISTRIBUTION_TYPE, DESTINATION_ID, TO_DIRECTORY, EMAIL_LIST, FTP_LOGIN_ID, FTP_DESTINATION, DISTRIBUTION_ID) 
	VALUES ( 
		S.DISTRIBUTION_TYPE, S.DESTINATION_ID, S.TO_DIRECTORY, S.EMAIL_LIST, S.FTP_LOGIN_ID, S.FTP_DESTINATION, S.DISTRIBUTION_ID);
